package com.kuyou.ddhm_tv.fragment;

import android.bluetooth.BluetoothGatt;
import android.os.Bundle;
import android.util.Log;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.Button;
import android.widget.CompoundButton;
import android.widget.ImageButton;
import android.widget.Switch;
import android.widget.TextView;
import android.widget.Toast;

import androidx.annotation.NonNull;
import androidx.annotation.Nullable;
import androidx.fragment.app.Fragment;
import androidx.recyclerview.widget.GridLayoutManager;
import androidx.recyclerview.widget.RecyclerView;

import com.clj.fastble.callback.BleGattCallback;
import com.clj.fastble.data.BleDevice;
import com.clj.fastble.exception.BleException;
import com.kuyou.ddhm_tv.MainActivity;
import com.kuyou.ddhm_tv.R;
import com.kuyou.ddhm_tv.adapter.CategoryAdapter;
import com.kuyou.ddhm_tv.bean.HomeItemBean;
import com.kuyou.ddhm_tv.utils.BsJudge;

import java.util.ArrayList;
import java.util.List;

public class FBP extends Fragment implements View.OnClickListener{
    BleGattCallback bleGattCallback = new BleGattCallback() {
        @Override
        public void onStartConnect() {

        }

        @Override
        public void onConnectFail(BleDevice bleDevice, BleException exception) {

        }

        @Override
        public void onConnectSuccess(BleDevice bleDevice, BluetoothGatt gatt, int status) {
            mBleDevice = bleDevice;
            bluetoothGatt = gatt;
        }

        @Override
        public void onDisConnected(boolean isActiveDisConnected, BleDevice device, BluetoothGatt gatt, int status) {
            mBleDevice = null;
            bluetoothGatt = null;
        }
    };
    BluetoothGatt bluetoothGatt;
    BleDevice mBleDevice;
    TextView connect ,disconnect,tvBackground;
    TextView state;
    Switch swStaticPress;
    @Nullable
    @Override
    public View onCreateView(@NonNull LayoutInflater inflater, @Nullable ViewGroup container, @Nullable Bundle savedInstanceState) {
        return inflater.inflate(R.layout.f_bp,container,false);
    }

    @Override
    public void onViewCreated(@NonNull View view, @Nullable Bundle savedInstanceState) {
        super.onViewCreated(view, savedInstanceState);
        initView(view);
        initData();
    }

    public void initView(View view){
        state = view.findViewById(R.id.tv_state);
        connect = view.findViewById(R.id.btn_connect);
        disconnect = view.findViewById(R.id.btn_disconnect);
        tvBackground = view.findViewById(R.id.tv_bp);
        swStaticPress = view.findViewById(R.id.sw_static_press);
        disconnect.setEnabled(false);

        connect.setOnClickListener(this);
        disconnect.setOnClickListener(this);
        swStaticPress.setOnCheckedChangeListener(new CompoundButton.OnCheckedChangeListener() {
            @Override
            public void onCheckedChanged(CompoundButton compoundButton, boolean b) {

            }
        });
    }
    public void initData(){

        ((MainActivity)getActivity()).setBleGattCallback(bleGattCallback);
    }


    @Override
    public void onClick(View view) {
        switch (view.getId()){
            case R.id.btn_connect:
                ((MainActivity)getActivity()).dialog.remove();
                ((MainActivity)getActivity()).SearchDevice();
                break;
            case R.id.btn_disconnect:
            case R.id.sw_static_press:

        }
    }
}
